<template>
  <div>
    <el-row :gutter="10">
      <el-col :span="7">
        <zh-card title="分类数量(饼图)">
          <pie-echart :pie-data="categoryGoodsCount"></pie-echart>
        </zh-card>
      </el-col>
      <el-col :span="10">
        <zh-card title="不同城市商品销售">
          <map-echart :mapData="addressGoodSale"></map-echart> </zh-card
      ></el-col>
      <el-col :span="7">
        <zh-card title="分类商品数量(玫瑰图)">
          <rose-echart :roseData="categoryGoodsCount"></rose-echart> </zh-card
      ></el-col>
    </el-row>
    <!-- 下一行 -->
    <el-row :gutter="10" class="content-row">
      <el-col :span="12">
        <zh-card title="分类商品销量">
          <!-- <base-ecahrt :option="option"></base-ecahrt> -->
          <line-echart v-bind="categoryGoodsSale"></line-echart>
        </zh-card>
      </el-col>
      <el-col :span="12">
        <zh-card title="分类商品收藏">
          <bar-echart v-bind="categoryGoodsSale"></bar-echart>
        </zh-card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import { useStore } from '@/store'
import ZhCard from '@/base-ui/card'
import {
  pieEchart,
  roseEchart,
  lineEchart,
  barEchart,
  mapEchart
} from '@/components/page-echart'
// import BaseEcahrt from '@/base-ui/echart/idnex'
export default defineComponent({
  name: 'dashboard',
  components: {
    ZhCard,
    pieEchart,
    roseEchart,
    lineEchart,
    barEchart,
    mapEchart
    // BaseEcahrt
  },
  setup() {
    const store = useStore()
    store.dispatch('dashboard/getDashboradDataAction')
    const categoryGoodsCount = computed(() => {
      return store.state.dashboard.categoryGoodsCount.map((item: any) => {
        return { name: item.name, value: item.goodsCount }
      })
    })
    //
    const categoryGoodsSale = computed(() => {
      const xLabels: string[] = []
      const values: any = []
      const categoryGoodsSale = store.state.dashboard.categoryGoodsSale
      for (const item of categoryGoodsSale) {
        xLabels.push(item.name)
        values.push(item.goodsCount)
      }
      return { xLabels, values }
    })
    //
    const addressGoodSale = computed(() => {
      return store.state.dashboard.addressGoodsSale.map((item: any) => {
        return { name: item.address, value: item.count }
      })
    })
    return {
      // option
      categoryGoodsCount,
      categoryGoodsSale,
      addressGoodSale
    }
  }
})
</script>

<style scoped lang="less">
.content-row {
  margin-top: 10px;
}
</style>
